<template>
    <div class="photo-container">
       <!-- 大标题 -->
        <h3 class="title">{{photoinfo.title}}</h3>
        <!-- 子标题 -->
        <p class="sub-title">
            <span>发表时间：{{photoinfo.add_time|dateFormat}}</span>
            <span>点击：{{photoinfo.click}}次</span>
        </p>
        <hr>
        <!-- 缩略图区域 -->
        <div class="thumbs">
          <vue-preview :slides="imglist"></vue-preview>
        </div>
        <!-- 内容区域 -->
        <div class="content" v-html="photoinfo.content"></div>
        <!-- 评论区域 -->
        <comment-box :id="this.id"></comment-box>
    </div>
</template>
<script>
import { Toast } from 'mint-ui';
import comment from '../subcomponents/Comment';

export default {
  data() {
    return {
      photoinfo: {},
      id: this.$route.params.id,
      imglist: [],
    };
  },
  created() {
    this.getPhotoInfo();
    this.getImgList();
  },
  methods: {
    getPhotoInfo() {
      this.$http.get(`api/getimageInfo/${this.id}`).then((res) => {
        if (res.body.status === 0) {
          this.photoinfo = res.body.message[0];
        } else {
          Toast('加载图片详情失败……');
        }
      });
    },
    getImgList() { // 获取图片详情中缩略图列表
      this.$http.get(`api/getthumimages/${this.id}`).then((res) => {
        const that = this;
        if (res.body.status === 0) {
          res.body.message.forEach((element) => {
            const obj = { src: element.src, msrc: element.src, alt: '缩略图', w: 600, h: 400 };
            that.imglist.push(obj);
          });
        } else {
          Toast('获取缩略图列表失败……');
        }
      });
    },
  },
  components: {
    'comment-box': comment,
  },
};
</script>
<style lang="scss" scoped>
.photo-container{
    padding: 3px;
    .title{
        font-size: 15px;
        text-align: center;
        margin: 15px 0;
        color:#26A2FF;
    }
    .sub-title{
        font-size: 13px;
        // color:#226aff;
        display: flex;
        justify-content: space-between;
    }
    .content{
        font-size: 13px;
        line-height: 30px;
    }
    .thumbs{
      vue-preview{
        margin: 10px;
        box-shadow: 0 0 8px #999;
      }
    }
}
</style>

